﻿using System;
using System.Runtime.InteropServices.ComTypes;

namespace Tsanie.ShellExt.Definitions
{

    /// <summary>
    /// InfoTip Handler 的基类
    /// </summary>
    public abstract class InfoTipHandlerBase : PersistFileBase, IQueryInfo
    {

        #region - 构造 -

        protected InfoTipHandlerBase() { }

        #endregion

        #region - 公共属性 -

        /// <summary>
        /// 获取文件名
        /// </summary>
        public string Filename { get { return m_FileName; } }

        /// <summary>
        /// 获取扩展名
        /// </summary>
        public string Ext { get { return m_Ext; } }

        #endregion

        #region - 子类重写 -

        /// <summary>
        /// 返回提示文本
        /// </summary>
        /// <param name="Flags">Flags directing the handling of the item.</param>
        protected abstract string OnGetInfoTip(InfoTipOptions options);
        /// <summary>
        /// 返回InfoFlags
        /// </summary>
        protected virtual InfoFlags OnGetInfoFlags() { return InfoFlags.Cached; }

        #endregion

        #region - IQueryInfo 成员 -

        void IQueryInfo.GetInfoTip(InfoTipOptions options, out string text)
        {
            text = OnGetInfoTip(options);
        }
        void IQueryInfo.GetInfoFlags(out InfoFlags flag)
        {
            flag = OnGetInfoFlags();
        }

        #endregion

        #region - COM 组件注册 -

        [System.Runtime.InteropServices.ComRegisterFunction()]
        private static void ComReg(Type t)
        {
            Common.RegisterExtension(t, "{00021500-0000-0000-C000-000000000046}");
        }
        [System.Runtime.InteropServices.ComUnregisterFunction()]
        private static void ComUnreg(Type t)
        {
            Common.UnregisterExtension(t, "{00021500-0000-0000-C000-000000000046}");
        }

        #endregion
    }

}
